#ifndef ANATOMICALREGION_H
#define ANATOMICALREGION_H

#include <QObject>
#include <vtkActor.h>
#include <regioninfo.h>
#include <vtkMapper.h>
#include <vtkRenderer.h>
#include <vtkPolyData.h>
#include <vtkContourFilter.h>
#include <vtkImageThreshold.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSet.h>
#include <vtkAlgorithmOutput.h>
#include <vtkImageData.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkSphereSource.h>
#include <stdlib.h>

class AnatomicalRegion : public QObject
{
public:
    AnatomicalRegion(const RegionInfo &rInfo);
    AnatomicalRegion(const AnatomicalRegion &aRegion);
    ~AnatomicalRegion();

    AnatomicalRegion& operator=(const AnatomicalRegion& rhs);
    bool operator==(AnatomicalRegion aRegion);

    void extractPolyDataFrom(vtkDataSet *dataSet);
	void loadPolyDataFromFile(std::string fullpath);

    void attachToRenderer(vtkRenderer *renderer);
    void detachFromRenderer(vtkRenderer *renderer);

    vtkActor *getNodeActor();
    void getColor(double col[3]);
	void setColor(double col[3]);
	void setOpacity(double opac);
	void resetColor();

	vtkPolyData *getData();
    void setVisible(bool visible);
	void setLinkNodeVisible(bool vis);
    bool equals(AnatomicalRegion *reg);
	void setSphereRadius(double absCor,double min, double max);
    RegionInfo& info() const;
    int NodeRefCount;
    
private:
	void createActorAndMapper(vtkPolyData *data);
	void createRegionSphere();
	vtkSphereSource *ssource;
	RegionInfo rinfo;
    vtkActor *actor;
    vtkActor *nodeActor;
    vtkPolyDataMapper *mapper;
    vtkPolyDataMapper *nodeMapper;
    vtkActor *contourActor;
    vtkMapper *contourMapper;
    vtkPolyData *data;
    double color[3];
    
    static const int MAXRADIUS = 5;
    static const int MINRADIUS = 1;

};

#endif // ANATOMICALREGION_H
